route.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { ApiPath } from "@/app/constant";
  2. import { NextRequest, NextResponse } from "next/server";
  3. import { handle as openaiHandler } from "../../openai";
  4. import { handle as azureHandler } from "../../azure";
  5. import { handle as googleHandler } from "../../google";
  6. import { handle as anthropicHandler } from "../../anthropic";
  7. import { handle as baiduHandler } from "../../baidu";
  8. import { handle as bytedanceHandler } from "../../bytedance";
  9. import { handle as alibabaHandler } from "../../alibaba";
  10. import { handle as moonshotHandler } from "../../moonshot";
  11. import { handle as stabilityHandler } from "../../stability";
  12. async function handle(
  13. req: NextRequest,
  14. { params }: { params: { provider: string; path: string[] } },
  15. ) {
  16. const apiPath = `/api/${params.provider}`;
  17. console.log(`[${params.provider} Route] params `, params);
  18. switch (apiPath) {
  19. case ApiPath.Azure:
  20. return azureHandler(req, { params });
  21. case ApiPath.Google:
  22. return googleHandler(req, { params });
  23. case ApiPath.Anthropic:
  24. return anthropicHandler(req, { params });
  25. case ApiPath.Baidu:
  26. return baiduHandler(req, { params });
  27. case ApiPath.ByteDance:
  28. return bytedanceHandler(req, { params });
  29. case ApiPath.Alibaba:
  30. return alibabaHandler(req, { params });
  31. // case ApiPath.Tencent: using "/api/tencent"
  32. case ApiPath.Moonshot:
  33. return moonshotHandler(req, { params });
  34. case ApiPath.Stability:
  35. return stabilityHandler(req, { params });
  36. default:
  37. return openaiHandler(req, { params });
  38. }
  39. }
  40. export const GET = handle;
  41. export const POST = handle;
  42. export const runtime = "edge";
  43. export const preferredRegion = [
  44. "arn1",
  45. "bom1",
  46. "cdg1",
  47. "cle1",
  48. "cpt1",
  49. "dub1",
  50. "fra1",
  51. "gru1",
  52. "hnd1",
  53. "iad1",
  54. "icn1",
  55. "kix1",
  56. "lhr1",
  57. "pdx1",
  58. "sfo1",
  59. "sin1",
  60. "syd1",
  61. ];